// @ts-nocheck
import { createApp, Directive } from 'vue'
import App from "./App.vue"
const app = createApp(App)
import config from '@/config'
import store from 'store'
//配置文件注入
// app.provide('config', 'hello')

//全局状态机
import { createPinia } from 'pinia'
const pinia = createPinia()
app.use(pinia)

// 路由
import router from '@/router'

//处理页面刷新导致的页面空白
import {ry_addRouter} from '@/router/index.ts'
const routerInfo = store.get('routerInfo')
if (routerInfo){
    // @ts-ignore
    await ry_addRouter()
}

// 警告错误提示
// 屏蔽错误信息
// app.config.errorHandler = () => null;
// 屏蔽警告信息
app.config.warnHandler = () => null;


import * as ElementPlusIconsVue from '@element-plus/icons-vue'
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}


//全局指令，判断是否有按钮的操作权限
// 定义一个全局自定义指令
const power: Directive = {
    beforeMount(el, binding, vnode) {
        // 在这里执行你的逻辑，比如修改元素的样式或属性
    },
    mounted(el, binding) {
        const permissions = store.get('permissions')
        const powerString = binding.value
        if (binding.value == undefined || binding.value == ''){
            el.style.display = 'block'
        }else{
            if (permissions.toString() == ['*:*:*']){ //高级管理员
                el.style.display = 'block';
            }else{
                if (permissions.indexOf(powerString) > -1){
                    el.style.display = 'block';
                }else{
                    el.style.display = 'none';
                }
            }
        }

    }
}
app.directive('power', power);
app.use(router)


//element.plus ui
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
app.use(ElementPlus)

// 全局组件
// import HelloWorld from './components/HelloWorld.vue'
// app.component('HelloWorld', HelloWorld)




//混入
import common from './mixin/common.ts'
app.mixin(common)


// 提示类 注：已在混入中注入
// import Tell from './wos/console/console.ts'
// let tell =  new Tell(config)
// app.provide('tell', tell)

app.mount('#app')